import { _decorator, Component, Label, Node } from 'cc';
import { Global } from './Global';
const { ccclass, property } = _decorator;

@ccclass('ShowLevelAction')
export class ShowLevelAction extends Component {

    @property({type:Label})
    level_label:Label = null;

    start() {
        if (!this.level_label) {
            console.error("ShowLevelAction: level_label UI 节点未绑定");
            // 可选：自动创建默认 Label 节点
            const labelNode = new Node("LevelLabel");
            this.level_label = labelNode.addComponent(Label);
            this.node.addChild(labelNode);
        }
    }

    update(deltaTime: number) {
        
    }

    // 显示当前等级
    show_level(){
        // 如果等级标签存在
        if(this.level_label){
            // 将等级标签的字符串设置为当前等级
            this.level_label.string = Global.cur_lvl + "";
        } else {
            console.warn("ShowLevelAction: level_label 未绑定");
        }
    }
}

